package com.yango.teach.controller.front;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yango.commonutil.result.Result;
import com.yango.teach.entity.Course;
import com.yango.teach.entity.Teacher;
import com.yango.teach.entity.vo.TeacherQuery;
import com.yango.teach.service.CourseService;
import com.yango.teach.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前台网站讲师 前端控制器
 * </p>
 *
 * @author LiDingYin
 * @since 2021-07-21
 */
@Api(description = "前台网站讲师 前端控制器")
@RestController
@RequestMapping("/teach/front/teacher")
public class TeacherFrontController {

    //注入service
    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    //1 分页查询讲师列表
    @ApiOperation(value = "条件查询带分页")
    @GetMapping("/pageList/{current}/{limit}")
    public Result pageList(@ApiParam(name = "current", value = "当前页", required = true)
                           @PathVariable long current,
                           @ApiParam(name = "limit", value = "每页显示记录数", required = true)
                           @PathVariable long limit) {
        //创建page对象,传入当前页和每页记录数
        Page<Teacher> page = new Page<>(current, limit);
        //调用分页方法
        teacherService.page(page, null);
        List<Teacher> records = page.getRecords();//记录集合
        long total = page.getTotal();//总记录数
        return Result.ok().data("items", records).data("total", total);
    }

    //根据讲师id查询讲师详情信息
    @ApiOperation(value = "根据讲师id查询讲师详情信息")
    @GetMapping("/getTeacherById/{teacherId}")
    public Result getTeacherById(@ApiParam(name = "teacherId", value = "讲师id", required = true)
                                 @PathVariable String teacherId) {
        //根据讲师id查询讲师信息
        Teacher teacher = teacherService.getById(teacherId);
        //根据讲师id查询讲师所讲课程
        List<Course> courseList = courseService.getByTeacherId(teacherId);
        return Result.ok().data("teacher", teacher).data("courseList", courseList);
    }

}

